/**
*      author: Y_Yao
*      created: 2024-12-28 18:15:53
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 1e18;
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 7;
int cnt[N];
int a[N];
int w[N];
int n;


void solve()
{
    cin >> n;
    unordered_map<int,priority_queue<int,vector<int>,greater<int>>> hash;
    for(int i = 1;i <= n;i++)
    {
        cin >> a[i];
    }
    for(int i = 1;i <= n;i++)
    {
        cin >> w[i];
    }

    for(int i = 1;i <= n;i++)
    {
        hash[a[i]].push(w[i]);
    }

    int ans = 0;
    for(auto& e : hash)
    {
        if(e.second.size() == 1)continue;
        while(e.second.size() != 1)
        {
            ans += e.second.top();
            e.second.pop();
        }
    }

    cout << ans << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}